package com.threeox.commonlibrary.entity.engine.model.multipage;

import com.threeox.commonlibrary.entity.base.BaseObj;
import com.threeox.commonlibrary.entity.engine.event.FragmentMsg;
import com.threeox.commonlibrary.entity.engine.event.ViewMessage;
import com.threeox.utillibrary.util.EmptyUtils;
import com.threeox.utillibrary.util.res.IdHelper;
import com.threeox.utillibrary.util.res.StringHelper;

/**
 * 
 * @ClassName: PageDataMessage
 * 
 * @Description: TODO(单个页面的对象)
 * 
 * @author 赵屈犇
 * 
 * @date 创建时间: 2017/8/10 15:59
 * 
 * @version 1.0
 * 
 */
public class PageDataMessage extends BaseObj {

    /*=============导航指示器设置================*/
    private String title;// 导航条的标题名称
    private Integer iconId;// 图标资源的Id
    private String iconName;// 图标的名称
    private Integer navBgId;// 背景Drawable的ID
    private String navBgName;// 背景Drawable的名称
    private Class indicatorViewClass;// 指示器view的类
    private String indicatorViewClassName;// 指示器view的类全名
    /*=============导航指示器设置================*/

    /*=============内容设置================*/
    private FragmentMsg fragment;// 内容为Fragment
    private ViewMessage viewMessage;// 内容为自定义VIew
    /*=============内容设置================*/

    public void initData(StringHelper stringHelper, IdHelper idHelper, Class indicatorViewClass) {
        try {
            setTitle(stringHelper.getStringText(title));
            if (EmptyUtils.isNotEmpty(getIconName())) {// 设置图标
                setIconId(idHelper.getIdByName(getIconName(), IdHelper.ResType.mipmap));
                if (EmptyUtils.isEmpty(getIconId())) {
                    setIconId(idHelper.getIdByName(getIconName(), IdHelper.ResType.drawable));
                }
            }
            if (EmptyUtils.isNotEmpty(getNavBgName())) {// 设置标题的背景
                setNavBgId(idHelper.getIdByName(getNavBgName(), IdHelper.ResType.mipmap));
                if (EmptyUtils.isEmpty(getNavBgId())) {
                    setNavBgId(idHelper.getIdByName(getNavBgName(), IdHelper.ResType.drawable));
                }
            }
            if (EmptyUtils.isNotEmpty(indicatorViewClassName)) {
                this.indicatorViewClassName = stringHelper.getStringText(indicatorViewClassName);
                this.indicatorViewClass = Class.forName(this.indicatorViewClassName);
            }
            if (this.indicatorViewClass == null && indicatorViewClass != null) {
                this.indicatorViewClass = indicatorViewClass;
            }
            if (EmptyUtils.isNotEmpty(fragment)) {
                fragment.initData(stringHelper);
            }
            if (EmptyUtils.isNotEmpty(viewMessage)) {
                viewMessage.initData(stringHelper);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getIconId() {
        return iconId;
    }

    public void setIconId(Integer iconId) {
        this.iconId = iconId;
    }

    public String getIconName() {
        return iconName;
    }

    public void setIconName(String iconName) {
        this.iconName = iconName;
    }

    public Integer getNavBgId() {
        return navBgId;
    }

    public void setNavBgId(Integer navBgId) {
        this.navBgId = navBgId;
    }

    public String getNavBgName() {
        return navBgName;
    }

    public void setNavBgName(String navBgName) {
        this.navBgName = navBgName;
    }

    public Class getIndicatorViewClass() {
        return indicatorViewClass;
    }

    public void setIndicatorViewClass(Class indicatorViewClass) {
        this.indicatorViewClass = indicatorViewClass;
    }

    public String getIndicatorViewClassName() {
        return indicatorViewClassName;
    }

    public void setIndicatorViewClassName(String indicatorViewClassName) {
        this.indicatorViewClassName = indicatorViewClassName;
    }

    public FragmentMsg getFragment() {
        return fragment;
    }

    public void setFragment(FragmentMsg fragment) {
        this.fragment = fragment;
    }

    public ViewMessage getViewMessage() {
        return viewMessage;
    }

    public void setViewMessage(ViewMessage viewMessage) {
        this.viewMessage = viewMessage;
    }

    /**
     * 初始化參數
     *
     * @param data
     */
    public void initParam(Object data) {
        if (null != fragment) {
            fragment.initParam(data);
        }
        if (null != viewMessage) {
            viewMessage.initParam(data);
        }
    }
}
